//
//  BBDistortionMesh.h
//  BBTouch
//
//  Created by ben smith on 8/12/08.
//  This file is part of BBTouch.
//
//  BBTouch is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.

//  BBTouch is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.

//  You should have received a copy of the GNU Lesser General Public License
//  along with BBTouch.  If not, see <http://www.gnu.org/licenses/>.
// 
//  Copyright 2008 Ben Britten Smith ben@benbritten.com .
//

#import <Cocoa/Cocoa.h>

// holds all the points of a single mesh
// mesh 

@class BBIndexedVertex;

@interface BBDistortionMesh : NSObject {
	NSInteger width; // the number of vertices across the horizontal axis
	NSInteger height; // the number of vertices across the vertical axis
	NSMutableArray * vertices; // stores all the points, order is very important
	NSRect boundingRect; // the smallest rectangle that encloses all the vertices
}

@property (assign) NSInteger width;
@property (assign) NSInteger height;
@property (retain) NSMutableArray * vertices;
@property (assign) NSRect boundingRect;

+ (BBDistortionMesh*)meshWithHeight:(NSInteger)h width:(NSInteger)w boundingRectangle:(NSRect)boundingRectangle;
- (BOOL)point:(NSPoint)p inTriangleA:(NSPoint)a b:(NSPoint)b c:(NSPoint)c;
- (NSArray*)boundingTriangleForPoint:(NSPoint)p;;
- (NSDictionary*)propertyDictionary;
- (NSPoint)destinationPointFromSourcePoint:(NSPoint)srcP
														sourceVertices:(NSArray*)verts;
- (NSPoint)destinationPointFromSourcePoint:(NSPoint)srcP
														 sourceVertexA:(BBIndexedVertex*)sa
														 sourceVertexB:(BBIndexedVertex*)sb
														 sourceVertexC:(BBIndexedVertex*)sc;
- (NSRect)boundingRect;
- (float)areaOfTriangleWithPoints:(NSPoint)p1 b:(NSPoint)p2 c:(NSPoint)p3;
- (float)dotA:(NSPoint)a b:(NSPoint)b;
- (id) init;
- (id)initWithCoder:(NSCoder *)coder;
- (void) dealloc;
- (void)addVertexAtPoint:(NSPoint)p;
- (void)calculateBoundingRect;
- (void)encodeWithCoder:(NSCoder *)coder;
- (void)flipMeshHorizontally;
- (void)flipMeshVertically;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;
- (void)rotateMeshInRadians:(float)theta;
- (void)scaleBoundingRectToNewRect:(NSRect)newRect;

// 20 methods



@end
